
var changed = false;

function setupLoadProductTexts(url) {
	$(document).ready(
		function() { 
			$("#name").change( function() { changed = true; } );
			$("#description").change( function() { changed = true; } );
			
			$("#selectLanguage").click( function() {
					if ( changed ) {
						alert("If you switch the language, all changes will be lost.");
						changed = false;
					}					
				}
			)
			$("#selectLanguage").change( function() {				
					$("#loading").html("loading").show();	
					$.get(url, 
						{id: $("#productId").val(), langId: $("#selectLanguage option:selected:first").val()}, 
							function(json) {								
								var data = eval('(' + json + ')');		
								$("#name").val("");
								$("#name").val(data.name);
								$("#description").val("");
								$("#description").val(data.description);
								$("#loading").text("loading").fadeOut(500);
								$("#languageId").val($("#selectLanguage option:selected:first").val());
								changed = false;								
							}
						)					
				}
			)
		});
}